<?php
//时间处理函数，整形->数组 以及 数组->整形
function time_turnint($yea,$mon,$day,$hou,$min,$sec)
{
	$int=($hou-8)*3600+$min*60+$sec;
	
	$month=array(31,28,31,30,31,30,31,31,30,31,30,31);
	for($i=0;$i<$mon-1;$i++)
	{
		$day+=$month[$i];
	}
	
	$i=$yea;
	while($i>1970)
	{
		if(!($i%4)&&($i%400))//是4的倍数，不是400的倍数，是闰年
			$day+=366;
		else
			$day+=365;	
		$i--;
	}
	$int+=$day*24*3600;
	return $int;
}
function time_turnarr($time)
{	
//时分秒---------------------
	$arr['sec']=$time%60;
	$time=(int)($time/60);
	$arr['min']=$time%60;
	$time=(int)($time/60);
	$time+=8;
	$arr['hou']=$time%24;
	$time=(int)($time/24);
//年-------------------------
	$i=1970;
	while(1)
	{
		if(!($i%4)&&($i%400))//是4的倍数，不是400的倍数，是闰年
		{
			$time-=366;
			if($time<0)
			{
				$time+=366;
				break;
			}
		}
		else
		{
			$time-=365;
			if($time<0)
			{
				$time+=365;
				break;
			}		
		}
		$i++;
	}
	$arr['yea']=$i;
	if((!$i%4)&&($i%400))
		$i=1;
	else 
		$i=0;
//月日----------------------------
	$month=array(31,28,31,30,31,30,31,31,30,31,30,31);
	$month[2]+=$i;
	for($j=0;$j<12;$j++)
	{
		$time-=$month[$j];
		if($time<0)
		{
			$arr['day']=$time+$month[$j];	
			$arr['mon']=$j+1;
			break;
		}
	}
	return $arr;
}
function time_echo($time,$i)
{
    if($time>1)
    {
        $arr=time_turnarr($time);
        if($i==1)
    		return $arr['yea'].'年'.$arr['mon'].'月'.$arr['day'].'日';
        else if($i==2)
            return $arr['yea'].'-'.$arr['mon'].'-'.$arr['day'].' '.$arr['hou'].':'.$arr['min'].':'.$arr['sec'];
    }
    else
        return NULL;
	
}

function time_show( $time ){
	$year_show = date( "Y" , $time );
    $mouth_show = date( "m" , $time );
    $day_show = date( "d" , $time );
	return $year_show.'年'.$mouth_show.'月'.$day_show.'日';
}
?>